package LeetCode_232;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/10/26 12:21
 * //232. 用栈实现队列
 */
class MyQueue {
    private final Deque<Integer> stack1 = new LinkedList<>();
    private final Deque<Integer> stack2 = new LinkedList<>();
    public MyQueue() {

    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if (empty()){
            return -1;
        }
        if (stack2.size()==0){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    public int peek() {
        if (empty()){
            return -1;
        }
        if (stack2.size()==0){
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.peek();
    }

    public boolean empty() {
        return stack1.isEmpty() && stack2.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */